import 'package:flutter/material.dart';
import 'package:my_flutter_tool/modle/comment.dart';
import 'package:my_flutter_tool/modle/user.dart';
import 'package:my_flutter_tool/widgets/app_text_field.dart';
import 'package:my_flutter_tool/widgets/app_checkbox.dart';

///评论回复输入框
class CommentFild extends StatefulWidget {
  const CommentFild({Key key, @required this.modle}) : super(key: key);
  final CommentModle modle;

  @override
  _CommentFildState createState() => _CommentFildState();
}

class _CommentFildState extends State<CommentFild> {
  TextEditingController _controller;

  @override
  void initState() {
    super.initState();
    _controller = TextEditingController(text: '');
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  ///发送评论
  _send() async {
    if (_controller.text.trim() != '') {
      widget.modle.addFloor(_controller.text, User(name: '张三'));
      _controller.clear();
    }
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
        color: Colors.white,
        padding:
            EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
        child: Column(
          children: [
            Container(
              height: 50,
              child: AppTextField(
                controller: _controller,
                autofocus: true,
                radius: 0,
                hintText: '添加一条友善的评论...',
                suffixIcon: IconButton(
                  icon: const Icon(Icons.send),
                  onPressed: () async {
                    await _send();
                  },
                ),
              ),
            ),
            SizedBox(
              height: 50,
              child: Padding(
                padding: EdgeInsets.symmetric(horizontal: 20),
                child: Row(
                  children: [
                    AppCheckBox(
                      onChange: (v) {},
                    ),
                    Text(
                      '  同时分享到动态',
                      style: TextStyle(
                        color: Colors.grey,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
